package cn.terminus.biz.customer.contractrentclause;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.contractrentclause.dto.*;
import cn.terminus.data.customer.contractrentclause.dao.ContractRentClauseDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 合同租金条款(ContractRentClause)表服务实现类
 *
 * @author makejava
 * @since 2021-07-21 11:01:11
 */
@Component
public class ContractRentClauseManager extends AbstractTerminusManager {
    @Autowired
    private ContractRentClauseDao contractRentClauseDao;

    public Integer add(ContractRentClauseNewDto dto) throws DataAccessException {
        try {
            return contractRentClauseDao.add(dto);
        } catch (Exception e) {
            logger.error("ContractRentClauseManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(ContractRentClauseEditDto dto) throws DataAccessException {
        try {
            return contractRentClauseDao.update(dto);
        } catch (Exception e) {
            logger.error("ContractRentClauseManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractRentClauseResultDto> gets(ContractRentClauseGetsDto dto) throws DataAccessException {
        try {
            return contractRentClauseDao.gets(dto);
        } catch (Exception e) {
            logger.error("ContractRentClauseManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractRentClauseResultDto> query(ContractRentClauseQueryDto dto) throws DataAccessException {
        try {
            return contractRentClauseDao.query(dto);
        } catch (Exception e) {
            logger.error("ContractRentClauseManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(ContractRentClauseDeleteDto dto) throws DataAccessException {
        try {
            return contractRentClauseDao.delete(dto);
        } catch (Exception e) {
            logger.error("ContractRentClauseManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<ContractRentClauseResultDto> page(ContractRentClauseQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<ContractRentClauseResultDto> result = (Page<ContractRentClauseResultDto>) contractRentClauseDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), ContractRentClauseResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("ContractRentClauseManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer deleteWithContractId(Long contractId) throws DataAccessException {

        try {
            return contractRentClauseDao.deleteWithContractId(contractId);
        } catch (Exception e) {
            logger.error("ContractRentClauseManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
